import {createApp} from 'vue'
import naive from 'naive-ui'
import App from './App.vue'
import 'virtual:uno.css'
import './style.css'

// 生产环境禁用开发者工具
if (import.meta.env.PROD) {
  // 禁用右键菜单
  document.addEventListener('contextmenu', (e) => e.preventDefault())
  
  // 禁用开发者工具快捷键
  document.addEventListener('keydown', (e) => {
    // F12
    if (e.key === 'F12') {
      e.preventDefault()
      return false
    }
    // Ctrl+Shift+I (Chrome DevTools)
    if (e.ctrlKey && e.shiftKey && e.key === 'I') {
      e.preventDefault()
      return false
    }
    // Ctrl+Shift+J (Chrome Console)
    if (e.ctrlKey && e.shiftKey && e.key === 'J') {
      e.preventDefault()
      return false
    }
    // Ctrl+Shift+C (Chrome Inspect)
    if (e.ctrlKey && e.shiftKey && e.key === 'C') {
      e.preventDefault()
      return false
    }
    // Ctrl+U (查看源代码)
    if (e.ctrlKey && e.key === 'u') {
      e.preventDefault()
      return false
    }
    // Ctrl+S (保存页面)
    if (e.ctrlKey && e.key === 's') {
      e.preventDefault()
      return false
    }
  })

  // 检测开发者工具是否打开
  const detectDevTools = () => {
    const threshold = 160
    const widthDiff = window.outerWidth - window.innerWidth > threshold
    const heightDiff = window.outerHeight - window.innerHeight > threshold
    if (widthDiff || heightDiff) {
      window.close()
    }
  }
  setInterval(detectDevTools, 1000)
}

const app = createApp(App)
app.use(naive)
app.mount('#app')
